/** @jsxImportSource @emotion/react */
import * as React from "react";
import {
    Button, TextArea,Text, useToast,
} from "customize-easy-ui-component";
import {
    InspectRecordLayout, InternalItemProps, useItemInputControl
} from "../../common/base";
import {管道级别} from "../../../device/edit/压力管道";
import {useMedia} from "use-media";
import {assertNamesUnique} from "../../common/eHelper";
import {itemA下结论} from "../editorDJ";
import {itemA宏观检验} from "./annAttach";        //绝对不能上import {itemA宏观检验} from "../editorMacr";  【同名地危险性】
import {itemA单特性} from "../EditorFeature";
import {EditStorageContext} from "../../StorageContext";

export const config设备概况 = [
    [['单位内编号', {n:'单位内编号',t:'B',l:['见管道特性表']}], ['起始—终止位置', {n:'起始终止',t:'B',l:['见管道特性表']}]],
    [['管道级别', {n:'管道级别',t:'l',l:管道级别}]],
    [['安全管理人员', '安全员'], ['联系电话', '安全员电']],
];

/**开启编制时的：默认值初始化操作。  若打印：本编辑器全部都不显示。
 * */
export const EntranceSetup =
React.forwardRef((
    {children, show, alone = true, repId, verId, rep}: InternalItemProps, ref
) => {
    const atPrint = useMedia('print');
    const toast = useToast();
    const doCheckNames = React.useCallback((verId: string) => {
        //【承压更少项目】，那些属于公共模板目录的 分项报告的唯一性检查在对方自己检查看。'Projects',
        const result = assertNamesUnique([{value: rep?.tzFields},
            {value: config设备概况, type:'esnt'},
            {value:[...itemA下结论, ...itemA宏观检验, ...itemA单特性, ]},
            {value:['Projects', ]} ]);
        toast({title: "完成！", subtitle: result ? "没发现冲突" : "测试开关没开", intent: "success"});
    }, [rep,toast]);
    const {storage, setStorage} =React.useContext(EditStorageContext) as any;
    const getInpFilter = React.useCallback((par: any) => {
        const {_tblFixed, } =par||{};
        return {_tblFixed, };
    }, []);
    const {inp, setInp} = useItemInputControl({ref});
    if (atPrint) return null;
    else return (
        <InspectRecordLayout inp={inp} setInp={setInp} getInpFilter={getInpFilter} show={show}
                             alone={alone} label={'初始化本报告，默认值配置等'}>
            {process.env.REACT_APP_TEST==='true' && <><div>
                <Text variant="h5">构建开发模板时的工具：校验模板的存储name冲突；</Text>
                <Button intent='primary' onPress={() => doCheckNames(verId!)}>校验模板name唯一性</Button>
                <Text variant="h5">设置待测试表格的各列宽度：</Text>
                <TextArea value={storage?._tblFixed || ''} rows={2}
                          onChange={e => setStorage({ ...storage, _tblFixed: e.currentTarget.value || undefined}) }/>
            </div>
            </>
            }
            <hr/>
        </InspectRecordLayout>
    );
});

